const { ccclass, property } = cc._decorator;
declare let eManager,dbh,DBManager,i18n,JsonHttp;
import BaseView from "../../component/BaseView";
import HzMiniSelectIconList from "./HzMiniSelectIconList";
import UIHelper = require("../../component/UIHelper");
@ccclass
export default class RepairBaseView extends BaseView {
    @property(HzMiniSelectIconList)
    selectList: HzMiniSelectIconList = null;

    @property(cc.Node)
    guideNode: cc.Node = null;

    @property(sp.Skeleton)
    aniSpine: sp.Skeleton = null;

    @property(cc.Node)
    endNode: cc.Node = null;
    @property(cc.Node)
    btnClose: cc.Node = null;

    _point = 1;//第几步
    _isPlay = false;
    _Step = [];//关卡标识 用于icon名字 拼接
    _StepList = [];//一共多少个 小步骤
    _StepNum = 0;//一共多少关
    _guidePos = [];
    _isStart = false;//是否是剧情前触发
    onLoad() {
        super.onLoad();
        //@ts-ignore
        this._isStart = this.node.openParam;
    };

    onClose(){
    };

    start(){
        super.start();
        this.selectList.showList(this._Step, this._StepNum, 1);
        if(this.btnClose){
            this.btnClose.active = !this._isStart;
        }
    };

    showGuide(){
        let pos = this._guidePos[this._point-1];
        if(pos){
            this.guideNode.position = pos;
            this.guideNode.active = true;
        }
    };

    onClickPlay(){
        if(this._isPlay)
            return;
        this.guideNode.active = false;
        this.aniSpine.setCompleteListener(() => {
            this._point++;
            let curPoint = this._StepList[this._point - 1];
            if(curPoint == null){
                curPoint = this._StepList[this._StepList.length - 1];
            }
            this.selectList.showList(this._Step, this._StepNum, curPoint);
            this._isPlay = false;
            this.showGuide();
            this.showPlayEnd();
        });
        let str = this._point >= 10 ? "0" : "00";
        this.aniSpine.setAnimation(0, str + this._point, false);
        this._isPlay = true;
        this.playSound();
    };

    playSound(){
        
    };

    makeDot(){
        
    };
    showPlayEnd(){
        if(this._point <= this._StepList.length)
            return;
        this.endNode.active = true;
    };

    onClickEnd(isSkip){
        let next = this.params.next && this.params.next.shift();
        if (next) {
            UIHelper.openUI(next, {
                next: this.params.next
            })
            this.node.destroy();
        }
        this.makeDot();
    };

    onClickSkip(){
        this.onClickEnd(true);
    };
}
